package com.demo.chapter3lambda;

import java.util.function.Function;

/**组合实例
 * @author dell
 *
 */
public class CompositeDemo {

	public static String addHeader(String text){
		return "From Raoul, Mario and Alan: " + text;
	}

	public static String checkSpelling(String text){
		return text.replace("labda", "lambda");
	}

	public static String addFooter(String text){
		return text + "Kind regards";
	}

	public static void demo(){
		//Function<String, String> addHeader = text -> addHeader(text);
		//Function<String, String> addHeader = text -> CompositeDemo.addHeader(text);
		Function<String, String> addHeader = CompositeDemo::addHeader;
		//添加header再进行拼写检查再添加footer
		Function<String, String> pipe1 = addHeader.andThen(CompositeDemo::checkSpelling).andThen(CompositeDemo::addFooter);
		System.out.println(pipe1.apply("abc labda "));
		//添加header再添加footer
		Function<String, String> pipe2 = addHeader.andThen(CompositeDemo::addFooter);
		System.out.println(pipe2.apply("abc11 "));
	}

	public static void main(String[] args) {
		demo();
	}

}
